﻿using System.Windows;
using System.Windows.Controls;

namespace PLCWpfTest.Controls
{
    /// <summary>
    /// VariableDisplay.xaml 的交互逻辑
    /// </summary>
    public partial class VariableDisplay : UserControl
    {
        private static readonly DependencyProperty UnitProperty = DependencyProperty.Register(nameof(Unit), typeof(string), typeof(VariableDisplay), new PropertyMetadata("℃", null, UnitCoerceValueCallback));

        public VariableDisplay()
        {
            InitializeComponent();
        }

        public string Unit
        {
            get { return GetValue(UnitProperty).ToString(); }
            set { SetValue(UnitProperty, value); }
        }

        private static object UnitCoerceValueCallback(DependencyObject d, object baseValue)
        {
            if (baseValue == null)
            {
                return baseValue;
            }
            VariableDisplay variableDisplay = (VariableDisplay)d;
            string unit = baseValue.ToString();
            variableDisplay.UnitTB.Text = unit;
            return unit;
        }
    }
}
